<template>
  <el-row :gutter="20" class="panel-group">
    <el-col :xs="24" :sm="24" :lg="6" class="card-panel-col">
      <div class="card-panel radius10 plr10 ptb20 " style="background-color:#b583ed;" @click="handleSetLineChartData('newVisitis')">
        <div class="w100p">
          <div class="ftwhite bdbf justify-between mb20 pb10">
            <div class="mb10">{{ value1 }}縂充值（元）</div>
            <el-segmented v-model="value1" :options="options1" size="large" @change="(e) => change(e, '1')">
              <template #default="{ item }">
                <div class="flex-col">
                  <div>{{ item }}</div>
                  <div class="shortline" v-if="item == value1">
                  </div>
                  <div class="lineff" v-else></div>
                </div>

              </template>
            </el-segmented>
          </div>
          <count-to :start-val="0" :end-val="dataRecharge" :duration="3000" class="ft60" color="#ffffff" />
        </div>
      </div>
    </el-col>
    <el-col :xs="24" :sm="24" :lg="6" class="card-panel-col">
      <div class="card-panel radius10 plr10 ptb20" style="background-color:#4cc4f2;" @click="handleSetLineChartData('messages')">
        <div class="w100p">
          <div class="ftwhite bdbf justify-between mb20 pb10">
            <div class="mb10">{{ value2 }}縂提款（元）</div>

            <el-segmented v-model="value2" :options="options2" size="large" @change="(e) => change(e, '2')">
              <template #default="{ item }">
                <div class="flex-col">
                  <div>{{ item }}</div>
                  <div class="shortline" v-if="item == value2">
                  </div>
                  <div class="lineff" v-else></div>
                </div>

              </template>
            </el-segmented>
          </div>
          <count-to :start-val="0" :end-val="dataCash" :duration="3000" class="ft60" color="#ffffff" />
        </div>
      </div>
    </el-col>
    <el-col :xs="24" :sm="24" :lg="6" class="card-panel-col">
      <div class="card-panel radius10 plr10 ptb20" style="background-color:#feab85;" @click="handleSetLineChartData('purchases')">
        <div class="w100p">
          <div class="ftwhite bdbf justify-between mb20 pb10">
            <div class="mb10">{{ value3 }}縂消費（元）</div>

            <el-segmented v-model="value3" :options="options3" size="large" @change="(e) => change(e, '3')">
              <template #default="{ item }">
                <div class="flex-col">
                  <div>{{ item }}</div>
                  <div class="shortline" v-if="item == value3">
                  </div>
                  <div class="lineff" v-else></div>
                </div>

              </template>
            </el-segmented>
          </div>
          <count-to :start-val="0" :end-val="dataConsume" :duration="3000" class="ft60" color="#ffffff" />
        </div>
      </div>
    </el-col>
    <el-col :xs="24" :sm="24" :lg="6" class="card-panel-col">
      <div class="card-panel radius10 plr10 ptb20" style="background-color:#53edcf;" @click="handleSetLineChartData('shoppings')">
        <div class="w100p">
          <div class="ftwhite bdbf justify-between mb20 pb10">
            <el-segmented v-model="value5" :options="options5" size="large" @change="(e) => change(e, '5')">
              <template #default="{ item }">
                <div class="flex-col">
                  <div>{{ item }}</div>
                  <div class="shortline" v-if="item == value5">
                  </div>
                  <div class="lineff" v-else></div>
                </div>

              </template>
            </el-segmented>
            <el-segmented v-model="value4" :options="options4" size="large" @change="(e) => change(e, '4')">
              <template #default="{ item }">
                <div class="flex-col">
                  <div>{{ item }}</div>
                  <div class="shortline" v-if="item == value4">
                  </div>
                  <div class="lineff" v-else></div>
                </div>

              </template>
            </el-segmented>
          </div>
          <count-to :start-val="0" :end-val="dataIncome" :duration="3000" class="ft60 " color="#ffffff" />
        </div>
      </div>
    </el-col>
  </el-row>
</template>

<script setup>
import { defineComponent, ref, onMounted } from 'vue';
import { rechargeData, cashData, consumeData, incomeData } from '@/api/homePage.js'
import CountTo from '@/components/vue-count-to';
onMounted(() => {
  getRechargeData()
  getCashData()
  getConsumeData()
  getIncomeData()
})
const value1 = ref('本日')
const value2 = ref('本日')
const value3 = ref('本日')



const options1 = ['本日', '本周', '本月', '上月']
const options2 = ['本日', '本周', '本月', '上月']
const options3 = ['本日', '本周', '本月', '上月']


const value4 = ref('本日')
const options4 = ['本日', '本周', '本月', '上月']

const value5 = ref('陪玩佣金')
const options5 = ['陪玩佣金', '經紀人佣金']


const handleSetLineChartData = (type) => {
  // this.$emit('handleSetLineChartData', type);
}

// 数据筛选
const change = (e, type) => {
  console.log('分段器----', e, type)
  let currentIndex = 0
  let currentIndex2 = 0
  if (type == 1) {
    currentIndex = options1.findIndex((item, index) => item == e)
  } else if (type == 2) {
    currentIndex = options2.findIndex((item, index) => item == e)

  } else if (type == 3) {
    currentIndex = options3.findIndex((item, index) => item == e)

  } else if (type == 5) {
    currentIndex2 = options5.findIndex((item, index) => item == e)
  } else if (type == 4) {
    currentIndex = options4.findIndex((item, index) => item == e)
    console.log('==========', currentIndex2)

  }
  let myType = currentIndex + 1
  let from = currentIndex2 + 1
  // 充值数据
  if (type == 1) {
    getRechargeData(myType)
  }
  if (type == 2) {
    getCashData(myType)
  }
  if (type == 3) {
    getConsumeData(myType)
  }
  if (type == 4) {
    getIncomeData(myType, from)

  }
  if (type == 5) {
    getIncomeData(myType, from)
  }
}
const dataRecharge = ref(0)
// 获取充值
const getRechargeData = (type = 1) => {
  rechargeData({ type: type }).then((res) => {
    console.log('获取充值数据', res)
    dataRecharge.value = res.data

  })
}
const dataCash = ref(0)
// 获取提款
const getCashData = (type = 1) => {
  cashData({ type: type }).then((res) => {
    console.log('获取提款数据', res)
    dataCash.value = res.data
  })
}
const dataConsume = ref(0)
// 获取消费
const getConsumeData = (type = 1) => {
  consumeData({ type: type }).then((res) => {
    console.log('获取消费数据')
    dataConsume.value = res.data
  })
}

const dataIncome = ref(0)
// 获取收入，陪玩、经纪人佣金
const getIncomeData = (type = 1, from = 1) => {
  incomeData({ type: type, from: from }).then((res) => {
    console.log('获取收入数据')
    dataIncome.value = res.data
  })
}
</script>

<style lang="scss" scoped>
:deep(.el-segmented__item.is-selected) {
  color: #ffffff;
}

:deep(.el-segmented--large .el-segmented__item) {
  padding: 0px 6px;
}

.el-segmented {
  --el-segmented-color: #ffffff;
  --el-segmented-bg-color: transparent;
  --el-segmented-item-selected-color: #3a3f63;
  --el-segmented-item-selected-bg-color: transparent;
  --el-segmented-item-hover-bg-color: transparent;
  --el-segmented-item-hover-color: #ffffff;
  --el-segmented-item-active-bg-color: transparent;
}

.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 15px;
  }

  .card-panel {
    display: flex;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);
    flex-shrink: 0;

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px 0;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
